?use master
go
drop database chodientu
go
CREATE DATABASE chodientu
go
USE chodientu
GO

CREATE TABLE ACCOUNT
(
	USERNAME VARCHAR(10),
	PASSWORD VARCHAR(20),
	PRIMARY KEY(USERNAME)
)

/****** Object:  Table [dbo].[Shop]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Shop](
	[Mashop] [varchar](10) NOT NULL,
	[Username] [varchar](10),
	[Magiaodien] [varchar](10),
	[Tenshop] [nvarchar](50) NULL,
	[Loaishop] [nvarchar](20) NULL,
 CONSTRAINT [PK_Shop] PRIMARY KEY CLUSTERED 
(
	[Mashop] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Banquantri]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Banquantri](
	[Username] [varchar](10) NOT NULL,
	[Role] [int] NULL,
 CONSTRAINT [PK_Banquantri] PRIMARY KEY CLUSTERED 
(
	[Username] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Baiviet]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Baiviet](
	[Mabaiviet] [varchar](10) NOT NULL,
	[Noidung] [nvarchar](100) NULL,
	[Ngaydang] [datetime] NULL,
	[Theloai] [nvarchar](50) NULL,
	[Quyenriengtu] [nchar](10) NULL,
 CONSTRAINT [PK_Baiviet] PRIMARY KEY CLUSTERED 
(
	[Mabaiviet] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Dichvu]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Dichvu](
	[Madichvu] [varchar](10) NOT NULL,
	[Tendichvu] [nvarchar](50) NULL,
	[Giatien] [float] NULL,
 CONSTRAINT [PK_Dichvu] PRIMARY KEY CLUSTERED 
(
	[Madichvu] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Nguoimua]    Script Date: 10/21/2012 01:57:15 ******/
/*
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Nguoimua](
	[Username] [varchar](10) NOT NULL,
 CONSTRAINT [PK_Nguoimua] PRIMARY KEY CLUSTERED 
(
	[Username] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO*/
/****** Object:  Table [dbo].[Nguoiban]    Script Date: 10/21/2012 01:57:15 ******/
/*
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Nguoiban](
	[Username] [varchar](10) NOT NULL,
 CONSTRAINT [PK_Nguoiban] PRIMARY KEY CLUSTERED 
(
	[Username] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
*/
/****** Object:  Table [dbo].[Logo]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Logo](
	[URL] [varchar](100) NOT NULL,
	[Size] [varchar](15) NULL,
 CONSTRAINT [PK_Logo] PRIMARY KEY CLUSTERED 
(
	[URL] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Loaisanpham]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Loaisanpham](
	[Maloaisanpham] [varchar](10) NOT NULL,
	[Tenloai] [nvarchar](50) NULL,
 CONSTRAINT [PK_Loaisanpham] PRIMARY KEY CLUSTERED 
(
	[Maloaisanpham] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Giaodien]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Giaodien](
	[Magiaodien] [varchar](10) NOT NULL,
	[Tengiaodien] [nvarchar](50) NULL,
	[URL] [nchar](10) NULL,
 CONSTRAINT [PK_Giaodien] PRIMARY KEY CLUSTERED 
(
	[Magiaodien] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Sanpham]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Sanpham](
	[Masanpham] [varchar](10) NOT NULL,
	[Mashop] [varchar](10) NULL,
	[Tensanpham] [nvarchar](50) NULL,
	[loaisanpham] [varchar](10) NULL,
 CONSTRAINT [PK_Sanpham] PRIMARY KEY CLUSTERED 
(
	[Masanpham] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Thanhvien]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Thanhvien](
	[Username] [varchar](10) NOT NULL,
	[Hoten] [nvarchar](50) NULL,
	[Ngaysinh] [date] NULL,
	[Diachi] [nvarchar](100) NULL,
	[Sotaikhoan] [nchar](10) NULL,
	[Diemtichluy] [int] NULL,
 CONSTRAINT [PK_Thanhvien] PRIMARY KEY CLUSTERED 
(
	[Username] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Phieumuasanpham]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Phieumuasanpham](
	[Maphieumua] [nchar](10) NOT NULL,
	[Mashop] [varchar](10) NULL,
	[Username] [varchar](10) NULL,
	[Ngaylap] [datetime] NULL,
	[Tongtien] [float] NULL,
	[Nganhang] [nvarchar](50) NULL,
 CONSTRAINT [PK_Phieumuasanpham] PRIMARY KEY CLUSTERED 
(
	[Maphieumua] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Tintuc]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Tintuc](
	[Matintuc] [varchar](10) NULL,
	[banquantri] [varchar](10) NULL,
	[Tieuderutgon] [nvarchar](100) NULL,
	[Noidung] [text] NULL,
	[Mucdo] [int] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Tinnhan]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Tinnhan](
	[Matinnhan] [varchar](10) NOT NULL,
	[Username] [varchar](10) NULL,
	[Tieude] [nvarchar](100) NOT NULL,
	[Nguoigui] [varchar](10) NULL,
	[Nguoinhan] [varchar](10) NULL,
	[Ngaygoi] [datetime] NULL,
	[Noidungtinnhan] [text] NULL,
 CONSTRAINT [PK_Tinnhan] PRIMARY KEY CLUSTERED 
(
	[Matinnhan] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Blog]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Blog](
	[Mablog] [varchar](10) NOT NULL,
	[Username] [varchar](10) NULL,
	[Mabaiviet] [varchar](10) NULL,
 CONSTRAINT [PK_Blog] PRIMARY KEY CLUSTERED 
(
	[Mablog] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Binhluan]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Binhluan](
	[Mabinhluan] [varchar](10) NULL,
	[Username] [varchar](10) NULL,
	[Ngaydang] [datetime] NULL,
	[Noidung] [text] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Phieumuadichvu]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Phieumuadichvu](
	[Maphieumua] [varchar](10) NOT NULL,
	[Username] [varchar](10) NULL,
	[Tendichvu] [nvarchar](50) NULL,
	[Ngaymua] [datetime] NULL,
	[Handung] [datetime] NULL,
 CONSTRAINT [PK_Phieumuadichvu] PRIMARY KEY CLUSTERED 
(
	[Maphieumua] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Thacmac]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Thacmac](
	[Maraovat] [varchar](10) NOT NULL,
	[Banquantri] [varchar](10) NULL,
	[Username] [varchar](10) NULL,
	[Tieude] [nvarchar](100) NULL,
	[Noidung] [text] NULL,
 CONSTRAINT [PK_Thacmac] PRIMARY KEY CLUSTERED 
(
	[Maraovat] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Raovat]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Raovat](
	[Maraovat] [varchar](10) NOT NULL,
	[Username] [varchar](10) NULL,
	[TieuDe] [nvarchar](100) NULL,
	[NoiDung] [text] NULL,
 CONSTRAINT [PK_Raovat] PRIMARY KEY CLUSTERED 
(
	[Maraovat] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Quangcao]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Quangcao](
	[Maquangcao] [varchar](10) NULL,
	[Username] [varchar](10) NULL,
	[Logo] [varchar](100) NULL,
	[Tieude] [nvarchar](100) NULL,
	[Noidung] [text] NULL,
	[Loaiquangcao] [nchar](10) NULL,
	[ThoiGian] [datetime] NULL,
	[Giatien] [float] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Chitietphieumuasanpham]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Chitietphieumuasanpham](
	[Masanpham] [varchar](10) NOT NULL,
	[Maphieumuasanpham] [nchar](10) NOT NULL,
 CONSTRAINT [PK_Chitietphieumuasanpham] PRIMARY KEY CLUSTERED 
(
	[Masanpham] ASC,
	[Maphieumuasanpham] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Chitietphieumuadichvu]]]    Script Date: 10/21/2012 01:57:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Chitietphieumuadichvu]]](
	[Madichvu] [varchar](10) NOT NULL,
	[Maphieumuadichvu] [varchar](10) NOT NULL,
 CONSTRAINT [PK_Chitietphieumuadichvu]]] PRIMARY KEY CLUSTERED 
(
	[Madichvu] ASC,
	[Maphieumuadichvu] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  ForeignKey [FK_Binhluan_Thanhvien]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Binhluan]  WITH CHECK ADD  CONSTRAINT [FK_Binhluan_Thanhvien] FOREIGN KEY([Username])
REFERENCES [dbo].[Thanhvien] ([Username])
GO
ALTER TABLE [dbo].[Binhluan] CHECK CONSTRAINT [FK_Binhluan_Thanhvien]
GO
/****** Object:  ForeignKey [FK_Blog_Baiviet]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Blog]  WITH CHECK ADD  CONSTRAINT [FK_Blog_Baiviet] FOREIGN KEY([Mabaiviet])
REFERENCES [dbo].[Baiviet] ([Mabaiviet])
GO
ALTER TABLE [dbo].[Blog] CHECK CONSTRAINT [FK_Blog_Baiviet]
GO
/****** Object:  ForeignKey [FK_Blog_Thanhvien]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Blog]  WITH CHECK ADD  CONSTRAINT [FK_Blog_Thanhvien] FOREIGN KEY([Username])
REFERENCES [dbo].[Thanhvien] ([Username])
GO
ALTER TABLE [dbo].[Blog] CHECK CONSTRAINT [FK_Blog_Thanhvien]
GO
/****** Object:  ForeignKey [FK_Chitietphieumuadichvu]]_Dichvu]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Chitietphieumuadichvu]]]  WITH CHECK ADD  CONSTRAINT [FK_Chitietphieumuadichvu]]_Dichvu] FOREIGN KEY([Madichvu])
REFERENCES [dbo].[Dichvu] ([Madichvu])
GO
ALTER TABLE [dbo].[Chitietphieumuadichvu]]] CHECK CONSTRAINT [FK_Chitietphieumuadichvu]]_Dichvu]
GO
/****** Object:  ForeignKey [FK_Chitietphieumuadichvu]]_Phieumuadichvu]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Chitietphieumuadichvu]]]  WITH CHECK ADD  CONSTRAINT [FK_Chitietphieumuadichvu]]_Phieumuadichvu] FOREIGN KEY([Maphieumuadichvu])
REFERENCES [dbo].[Phieumuadichvu] ([Maphieumua])
GO
ALTER TABLE [dbo].[Chitietphieumuadichvu]]] CHECK CONSTRAINT [FK_Chitietphieumuadichvu]]_Phieumuadichvu]
GO
/****** Object:  ForeignKey [FK_Chitietphieumuasanpham_Phieumuasanpham]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Chitietphieumuasanpham]  WITH CHECK ADD  CONSTRAINT [FK_Chitietphieumuasanpham_Phieumuasanpham] FOREIGN KEY([Maphieumuasanpham])
REFERENCES [dbo].[Phieumuasanpham] ([Maphieumua])
GO
ALTER TABLE [dbo].[Chitietphieumuasanpham] CHECK CONSTRAINT [FK_Chitietphieumuasanpham_Phieumuasanpham]
GO
/****** Object:  ForeignKey [FK_Chitietphieumuasanpham_Sanpham]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Chitietphieumuasanpham]  WITH CHECK ADD  CONSTRAINT [FK_Chitietphieumuasanpham_Sanpham] FOREIGN KEY([Masanpham])
REFERENCES [dbo].[Sanpham] ([Masanpham])
GO
ALTER TABLE [dbo].[Chitietphieumuasanpham] CHECK CONSTRAINT [FK_Chitietphieumuasanpham_Sanpham]
GO
/****** Object:  ForeignKey [FK_Giaodien_Shop]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Shop]  WITH CHECK ADD  CONSTRAINT [FK_Shop_Giaodien] FOREIGN KEY([Magiaodien])
REFERENCES [dbo].[Giaodien] ([Magiaodien])
GO
ALTER TABLE [dbo].[Shop] CHECK CONSTRAINT [FK_Shop_Giaodien]
GO
/****** Object:  ForeignKey [FK_Phieumuadichvu_Thanhvien]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Phieumuadichvu]  WITH CHECK ADD  CONSTRAINT [FK_Phieumuadichvu_Thanhvien] FOREIGN KEY([Username])
REFERENCES [dbo].[Thanhvien] ([Username])
GO
ALTER TABLE [dbo].[Phieumuadichvu] CHECK CONSTRAINT [FK_Phieumuadichvu_Thanhvien]
GO
/****** Object:  ForeignKey [FK_Phieumuasanpham_Nguoimua]    Script Date: 10/21/2012 01:57:15 ******/
/****** Object:  ForeignKey [FK_Phieumuasanpham_Shop]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Phieumuasanpham]  WITH CHECK ADD  CONSTRAINT [FK_Phieumuasanpham_Shop] FOREIGN KEY([Mashop])
REFERENCES [dbo].[Shop] ([Mashop])
GO
ALTER TABLE [dbo].[Phieumuasanpham] CHECK CONSTRAINT [FK_Phieumuasanpham_Shop]
GO
------------------------------
ALTER TABLE [dbo].[Shop]  WITH CHECK ADD  CONSTRAINT [FK_Shop_Thanhvien] FOREIGN KEY([Username])
REFERENCES [dbo].[Thanhvien] ([Username])
GO
ALTER TABLE [dbo].[Shop] CHECK CONSTRAINT [FK_Shop_Thanhvien]
GO
----------------------------------------------------
/****** Object:  ForeignKey [FK_Quangcao_Logo]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Quangcao]  WITH CHECK ADD  CONSTRAINT [FK_Quangcao_Logo] FOREIGN KEY([Logo])
REFERENCES [dbo].[Logo] ([URL])
GO
ALTER TABLE [dbo].[Quangcao] CHECK CONSTRAINT [FK_Quangcao_Logo]
GO
/****** Object:  ForeignKey [FK_Quangcao_Thanhvien]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Quangcao]  WITH CHECK ADD  CONSTRAINT [FK_Quangcao_Thanhvien] FOREIGN KEY([Username])
REFERENCES [dbo].[Thanhvien] ([Username])
GO
ALTER TABLE [dbo].[Quangcao] CHECK CONSTRAINT [FK_Quangcao_Thanhvien]
GO
/****** Object:  ForeignKey [FK_Raovat_Thanhvien]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Raovat]  WITH CHECK ADD  CONSTRAINT [FK_Raovat_Thanhvien] FOREIGN KEY([Username])
REFERENCES [dbo].[Thanhvien] ([Username])
GO
ALTER TABLE [dbo].[Raovat] CHECK CONSTRAINT [FK_Raovat_Thanhvien]
GO
/****** Object:  ForeignKey [FK_Sanpham_Loaisanpham]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Sanpham]  WITH CHECK ADD  CONSTRAINT [FK_Sanpham_Loaisanpham] FOREIGN KEY([loaisanpham])
REFERENCES [dbo].[Loaisanpham] ([Maloaisanpham])
GO
ALTER TABLE [dbo].[Sanpham] CHECK CONSTRAINT [FK_Sanpham_Loaisanpham]
GO
/****** Object:  ForeignKey [FK_Sanpham_Shop]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Sanpham]  WITH CHECK ADD  CONSTRAINT [FK_Sanpham_Shop] FOREIGN KEY([Mashop])
REFERENCES [dbo].[Shop] ([Mashop])
GO
ALTER TABLE [dbo].[Sanpham] CHECK CONSTRAINT [FK_Sanpham_Shop]
GO
/****** Object:  ForeignKey [FK_Thacmac_Banquantri]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Thacmac]  WITH CHECK ADD  CONSTRAINT [FK_Thacmac_Banquantri] FOREIGN KEY([Banquantri])
REFERENCES [dbo].[Banquantri] ([Username])
GO
ALTER TABLE [dbo].[Thacmac] CHECK CONSTRAINT [FK_Thacmac_Banquantri]
GO
/****** Object:  ForeignKey [FK_Thacmac_Thanhvien]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Thacmac]  WITH CHECK ADD  CONSTRAINT [FK_Thacmac_Thanhvien] FOREIGN KEY([Username])
REFERENCES [dbo].[Thanhvien] ([Username])
GO
ALTER TABLE [dbo].[Thacmac] CHECK CONSTRAINT [FK_Thacmac_Thanhvien]
GO
/****** Object:  ForeignKey [FK_Thanhvien_Nguoiban]    Script Date: 10/21/2012 01:57:15 ******/
/****** Object:  ForeignKey [FK_Thanhvien_Nguoimua]    Script Date: 10/21/2012 01:57:15 ******/
/****** Object:  ForeignKey [FK_Tinnhan_Thanhvien]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Tinnhan]  WITH CHECK ADD  CONSTRAINT [FK_Tinnhan_Thanhvien] FOREIGN KEY([Username])
REFERENCES [dbo].[Thanhvien] ([Username])
GO
ALTER TABLE [dbo].[Tinnhan] CHECK CONSTRAINT [FK_Tinnhan_Thanhvien]
GO
/****** Object:  ForeignKey [FK_Tintuc_Banquantri]    Script Date: 10/21/2012 01:57:15 ******/
ALTER TABLE [dbo].[Tintuc]  WITH CHECK ADD  CONSTRAINT [FK_Tintuc_Banquantri] FOREIGN KEY([banquantri])
REFERENCES [dbo].[Banquantri] ([Username])
GO
ALTER TABLE [dbo].[Tintuc] CHECK CONSTRAINT [FK_Tintuc_Banquantri]
GO

ALTER TABLE THANHVIEN
ADD CONSTRAINT FK_THANHVIEN_ACCOUNT
FOREIGN KEY(USERNAME)
REFERENCES ACCOUNT(USERNAME)

ALTER TABLE BANQUANTRI
ADD CONSTRAINT FK_BANQUANTRI_ACCOUNT
FOREIGN KEY(USERNAME)
REFERENCES ACCOUNT(USERNAME)